{% extends "base.html" %}
{% block title %}软件信息{% endblock %}
{% block head_ext %}
<script type="text/javascript">
	$(document).ready(function() {
		$.extend(jQuery.strConversion, 
            {'S': function(input, arg){ return input.safe(); }
        });
		
		$.tpl('download', 
		  ['<tr><td>{filesize}</td>',
		  '<td>{last_modified}</td>',
		  '<td><a href="{referer}" target="blank">地址{index}</a></td>',
		  '<td><a title="{realurl}" href="{realurl}" target="blank">下载地址{index}</a></td>',
		  '<td>{anti_navigate}</td></tr>']);
		
		$('h3 a.show-download').click(function() {
			var $a = $(this);
			var $h3 = $a.parent()
			var softkey = $a.attr('softkey')
			var url = '{% url get-soft-downloads "__key__" %}'.replace('__key__', softkey);
			$h3.next().remove();
			$h3.after('<p class="loading">Loading...</p>');
			$.getJSON(url,
                function(res){
                    if(res.success) {
						$h3.next().remove();
						if(res.downloads.length == 0) {
							$h3.after('<p>No downloads.</p>');
						} else {
							var $table = $('<table><tr><th>文件大小</th><th>最后更新</th><th>来源地址</th><th>直接下载地址</th><th>防盗链</th></tr></table>');
	                        $.each(res.downloads, function(index, download) {
	                            download.index = index + 1;
								download.filesize = filesize(download.filesize);
	                            $table.append($.tpl('download', download, true));
	                        });
							$h3.after($table);
						}
						$a.html('Refresh Downloads');
                    } else {
                        alert(res.message);
                    }
            });
			return false;
		});
	});
</script>
{% endblock %}
{% block main-content %}
<h1>无聊软件信息收集</h1>
<p>目前共收录: <strong>{{total}}</strong> 款软件信息 (难免出现重复)</p>
<p>
    {% if has_prev %}
    <a href="{% url get-softinfos %}">First</a>
    <a href="{% url get-softinfos %}?offset={{prev}}&limit={{limit}}">Prev</a>
    {% endif %}
    <a href="{% url get-softinfos %}?offset={{next}}&limit={{limit}}">Next</a>
</p>
{% for i in softinfos %}
<div id="soft_{{forloop.counter}}">
    <h2>{{i.key.id}}. <a href="{{i.url}}" title="{{i.name}}">{{i.name}}</a>
	{% if not i.name %}No soft info: {{i.url}}{% endif %}
	</h2>
    <ul>
    	<li><span>更新时间:</span> <span>{{i.last_modified}}</span></li>
	   	{% for k, v in i.load_info.items %}
		<li><span>{{k}}:</span> <span>{{v}}</span></li>
		{% endfor %}
    </ul>
	<h3><a  class="show-download" softkey="{{i.key}}" href="#">Show Downloads</a></h3>
</div>
{% endfor %}
<p>
    {% if has_prev %}
	<a href="{% url get-softinfos %}">First</a>
    <a href="{% url get-softinfos %}?offset={{prev}}&limit={{limit}}">Prev</a>
    {% endif %}
    <a href="{% url get-softinfos %}?offset={{next}}&limit={{limit}}">Next</a>
</p>
{% endblock %}